﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WL_Store.BLL;
using WL_Store.Model;

namespace WL_Store.Web.subpage
{
    public partial class Products_List_edit : System.Web.UI.Page
    {
        CommodityInfoBLL bll = new CommodityInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              int id=Convert.ToInt32(Request.QueryString["commodityID"]);
               

                CommodityInfoModel model = bll.commodity(id);
                if (model!=null)
                {
                    this.txt_number.Text = model.commodityID.ToString();
                    this.txt_nam.Text = model.comName;
                    this.txt_purchase.Text = model.purchase;
                    this.txt_selling.Text = model.selling;
                    this.txt_productionPlace.Text = model.productionPlace;
                    this.txt_stocks.Text = model.stocks.ToString();
                    this.txt_quantitySold.Text = model.quantitySold.ToString();
                    this.txt_description.Text = model.description;
                }

            }
        }

        protected void btn_edit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string commodityID = this.txt_number.Text;
                string comName = this.txt_nam.Text.Trim();
                string purchase = this.txt_purchase.Text.Trim();
                string selling = this.txt_selling.Text.Trim();
                string productionPlace = this.txt_productionPlace.Text.Trim();
                string stocks = this.txt_stocks.Text.Trim();
                string quantitySold = this.txt_quantitySold.Text.Trim();
                string description = this.txt_description.Text.Trim();

                int id = Convert.ToInt32(Request.QueryString["commodityID"]);

                CommodityInfoModel model = new CommodityInfoModel();
                model.commodityID = Convert.ToInt32(commodityID);
                model.comName = comName;
                model.purchase = purchase;
                model.selling = selling;
                model.productionPlace = productionPlace;
                model.stocks = Convert.ToInt32(stocks);
                model.quantitySold = Convert.ToInt32(quantitySold);
                model.description = description;

                if (bll.UpdateCommodityInfoProc(model))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script> parent.layer.msg('修改成功！', { time: 1000, shade: 0.3 },function(){parent.layer.close(parent.layer.getFrameIndex(window.name));})</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改失败！')</script>");
                }


            }
        }
    }
}